/**
 * this is the base module for search;
 */
(function($) {	
	$.my = $.my || {};
	function search(options) {
		var options = $.extend({
			source: 'google',
			type: options.type || 'websearch',
			lan: 'cn',
			page: 1,
			start: 1
		}, options);
		new google(options);
	}
	
	function google(options) {
		var seachUrl, params;
		var options = $.extend({
			start:1,
			page:1
		}, options);
		
		if(options.type && options.type != 'websearch'){
			params = {
					hl : 'zh-CN',
					ned : 'cn', //location for news
					lr : 'lang_zh_CN', //lan for web
					q: options.keyword,
					rsz: 8,
					start: options.start || 1,
					v:'1.0'
			};
			searchUrl = 'https://ajax.googleapis.com/ajax/services/search/'+ options.type +'?'+$.param(params) + '&callback=?';
		}else{
			params = {
				q: options.keyword,
				start: options.start || 1,
				rsz: 8,
				alt: 'json',
				key: 'AIzaSyDTSLLmHCuNW5a6YcIbbKcSFa2CC0DzghE',
				cx: '006880273249494668868:jvzc9svxwb8'
			};
			searchUrl = 'https://www.googleapis.com/customsearch/v1?'+$.param(params) + '&callback=?';
		}
		
		$.getJSON(searchUrl, function(data) {
			options.callback(data);
		});
		$.log(searchUrl);
		
	}
	
	$.my.Search = search;
})(jQuery);